package com.emerald.algorithm;

public class QuickFind {
	private int[] id;
	
	public QuickFind(int length){
		id = new int[length];
	}
	
	public boolean isConnected(int p, int q){
		return id[p] == id[q];
	}
	
	public void union(int p, int q){
		int x = id[p];
		int y = id[q];
		for(int i = 0; i < id.length; i++){
			if(id[i] == x){
				id[i] = y;
			}
		}
	}
}
